package common

import (
	"log"

	"time"

	"github.com/go-ini/ini"
)

var (
	Cfg          *ini.File
	HTTPPort     int
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	RunMode      string
)

func init() {
	var err error
	cfg, err := ini.Load("conf/app.ini")
	if err != nil {
		log.Fatal("error:cant not load 'conf/app.ini':%v", err)
	}

	Cfg = cfg

	LoadBase()
	LoadServer()

}

func LoadBase() {
	RunMode = Cfg.Section("").Key("RUN_MODE").MustString("debug")
}

func LoadServer() {
	sec, err := Cfg.GetSection("server")
	if err != nil {
		log.Fatal("err:cant not get section server :%v", err)
	}

	HTTPPort = sec.Key("HTTP_PORT").MustInt(8000)
	ReadTimeout = time.Duration(sec.Key("READ_TIMEOUT").MustInt(60)) * time.Second
	WriteTimeout = time.Duration(sec.Key("WRITE_TIMEOUT").MustInt(60)) * time.Second
}
